import createElement from "./createElement";
import updataChildren from "./updateChildren";
export default function patchVnode(oldVnode, newVnode) {
    //判断新旧vnode是否是同一个对象
    if (oldVnode === newVnode) return;
    // 判断新vnode又没有text属性
    if (newVnode.text != undefined && (newVnode.children == undefined || newVnode.children.length == 0)) {
        console.log('newVnode有text属性');
        if (newVnode.text != oldVnode.text) {
            oldVnode.elm.innerText = newVnode.text;
        }
    } else {
        console.log('newVnode没有text属性');
        // 判断oldvnode又没有children
        if (oldVnode.children != undefined && oldVnode.children.length > 0) {
            updataChildren(oldVnode.elm, oldVnode.children, newVnode.children)
        } else {
            oldVnode.elm.innerText = ''

            for (let i = 0; i < newVnode.children.length; i++) {
                let dom = createElement(newVnode.children[i])
                oldVnode.elm.appendChild(dom)
            }
        }
    }
}